import requests, re

# 注册(注意：此处有bug, 注册时后台未对验证码进行验证)

base_url = 'http://192.168.5.223'
email = 'test3@test.com'

# 获取注册时的token
url = base_url + "/Tiny2.4_data/index.php?con=simple&act=reg"
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
s = requests.session()
r = s.get(url, headers=headers)
tiny_token_reg = re.findall("tiny_token_reg\' value=\'(.*)\'/>", r.text)[0]
print(tiny_token_reg)

#   发送注册的请求
url = base_url + "/Tiny2.4_data/index.php?con=simple&act=reg_act"
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
datas = {'email': email,
         'password': '123456',
         'repassword': '123456',
         # 'verifyCode':'aaaa',     #bug
         'tiny_token_reg': '%s' % tiny_token_reg,
         }
r = s.post(url, data=datas)
# print(r.text)
tiny_token_redirect = re.findall('name="tiny_token_redirect" value="(.*)" /></', r.text)[0]
print(tiny_token_redirect)

#   验证注册成功与否
url = base_url + '/Tiny2.4_data/index.php?con=simple&act=reg_result'
datas = {'user_status': 1,
         'mail_host': 'http://mail.test.com',
         'user_name': email,
         'tiny_token_redirect': tiny_token_redirect}
r = s.post(url, data=datas)
if '注册成功' in r.text:
    print('注册成功')
else:
    print('注册失败')
